Move the URL link and text from C strings to QStrings.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 23 Mar 2013 21:09:32 +0000 (21:09 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 23 Mar 2013 21:09:32 +0000 (21:09 +0000)
git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4356 f51c46e8-681c-474f-0cfe-069cfd0219fb

16 files changed:
gpsbabel/an1.cc
gpsbabel/cet_util.cc
gpsbabel/cet_util.h
gpsbabel/cst.cc
gpsbabel/csv_util.cc
gpsbabel/defs.h
gpsbabel/gdb.cc
gpsbabel/html.cc
gpsbabel/kml.cc
gpsbabel/lmx.cc
gpsbabel/mmo.cc
gpsbabel/mtk_logger.cc
gpsbabel/navicache.cc
gpsbabel/tmpro.cc
gpsbabel/vcf.cc
gpsbabel/waypt.cc

index 64b7adf6d99d611f749eb54f2919e82f73c5a5c5..458afbba963702bd26ba221f62b686c192ec1394 100644 (file)
@@ -779,12 +779,12 @@ Write_One_AN1_Waypoint(const waypoint* wpt)
   }
 
   if (!nourl && wpt->hasLink()) {
-    int len = 7+strlen(wpt->url);
+    int len = 7 + wpt->url.length();
     char* extra = (char*)xmalloc(len);
-    sprintf(extra, "{URL=%s}", wpt->url);
+    sprintf(extra, "{URL=%s}", wpt->url.toUtf8().data());
     rec->name = xstrappend(rec->name, extra);
     xfree(extra);
-    rec->url = xstrdup(wpt->url);
+    rec->url = xstrdup(wpt->url.toUtf8().data());
   }
 
   if (wpt->notes) {
index 54b0e0898e2d84ad236fb9fa30f0253ebefe92d7..b86d73f0572c95e604d5b82a2b6afb79b9f96e4b 100644 (file)
@@ -1021,8 +1021,11 @@ cet_convert_string(char* str)
 }
 
 const char *
-cet_convert_string(QString str) {
-  return cet_convert_string(str.toUtf8().data());
+cet_convert_string(const QString& str) {
+  // FIXME: this is really weird.  Since cet_convert_string wants to free
+  // its argument (!) we make a duplicate just to satisfy that kind of goofy
+  // requirement.
+  return cet_convert_string(xstrdup(str.toUtf8().data()));
 }
 
 /* cet_convert_waypt: internal used within cet_convert_strings process */
index e01a73ef4af05ab5453fe86c7673f1431f127b4c..bc2ea1466f788830754f41bcd3861a2204be3c19 100644 (file)
@@ -109,7 +109,7 @@ int cet_gbfprintf(gbfile* stream, const cet_cs_vec_t* src_vec, const char* fmt,
 
 /* cet_convert_string: !!! ONLY VALID WITHIN 'cet_convert_strings' process !!! */
 char* cet_convert_string(char* str);
-const char* cet_convert_string(QString str);
+const char* cet_convert_string(const QString& str);
 
 /* gpsbabel extensions */
 
index ffe89401ae6072b78a545d3113a65c1999712aa9..7bdc32bbbf06f3caed16a9cf8f632c036dc5e956 100644 (file)
@@ -60,10 +60,14 @@ cst_add_wpt(const route_head* track, waypoint* wpt)
 
   if (wpt->shortname != NULL) {
     waypt_add(waypt_dupe(wpt));
+#if 0
     if (wpt->url != NULL) {
       xfree(wpt->url);
       wpt->url = NULL;
     }
+#else
+    wpt->url.clear();
+#endif
 
     if (temp_route == NULL) {
       temp_route = route_head_alloc();
index f7c9616a57a64ecd361391cd7e7b6351fa92955b..90456a4f98e13dbd3b7f8fd836c1805f4dcb72be 100644 (file)
@@ -1711,7 +1711,7 @@ xcsv_waypt_pr(const waypoint* wpt)
         off = strlen(xcsv_urlbase);
       }
       if (wpt->hasLink()) {
-        snprintf(buff + off, sizeof(buff) - off, fmp->printfc, wpt->url);
+        snprintf(buff + off, sizeof(buff) - off, fmp->printfc, wpt->url.toUtf8().data());
       } else {
         strcpy(buff, (fmp->val && *fmp->val) ? fmp->val : "\"\"");
       }
@@ -1719,7 +1719,7 @@ xcsv_waypt_pr(const waypoint* wpt)
     break;
     case XT_URL_LINK_TEXT:
       snprintf(buff, sizeof(buff), fmp->printfc,
-               (wpt->hasLinkText()) ? wpt->url_link_text : fmp->val);
+               (wpt->hasLinkText()) ? wpt->url_link_text.toUtf8().data() : fmp->val);
       break;
     case XT_ICON_DESCR:
       writebuff(buff, fmp->printfc,
index 5d23e9e8bc0f0cceb0f746b38c3856d1a94f23fd..414e328823f0124f9cee6158b7701e5fab067e0a 100644 (file)
@@ -371,13 +371,11 @@ fs_xml* fs_xml_alloc(long type);
 class url_link {
  public: 
     url_link() :
-    url_next(NULL),
-    url(NULL),
-    url_link_text(NULL)
+    url_next(NULL)
      {} ;
   url_link* url_next;
-  char* url;
-  char* url_link_text;
+  QString url;
+  QString url_link_text;
 };
 
 /*
@@ -461,8 +459,6 @@ public:
   description(NULL), 
   notes(NULL), 
   url_next(NULL), 
-  url(NULL), 
-  url_link_text(NULL), 
 #if NEWTIME
 //  creation_time(QDateTime::fromTime_t(0)),
 #else
@@ -537,10 +533,10 @@ public:
    * members must match struct url_link...
    */
   url_link* url_next;
-  bool hasLink() const {return url && *url; }
-  bool hasLinkText() const {return url_link_text && *url_link_text; }
-  char* url;
-  char* url_link_text;
+  bool hasLink() const {return !url.isEmpty(); }
+  bool hasLinkText() const {return !url_link_text.isEmpty(); }
+  QString url;
+  QString url_link_text;
 
   wp_flags wpt_flags;
   QString icon_descr;
@@ -688,7 +684,8 @@ void waypt_flush(queue*);
 void waypt_flush_all(void);
 unsigned int waypt_count(void);
 void set_waypt_count(unsigned int nc);
-void waypt_add_url(waypoint* wpt, char* link, char* url_link_text);
+void waypt_add_url(waypoint* wpt, const QString& link,
+                   const QString& url_link_text);
 void free_gpx_extras(xml_tag* tag);
 void xcsv_setup_internal_style(const char* style_buf);
 void xcsv_read_internal_style(const char* style_buf);
index 6a726651ecab9e226c0a35c40d4ce4a09ba6a6ce..09038461d943552e8029e20eacdef8720aed4436 100644 (file)
@@ -620,8 +620,8 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out)
 
     res->url = FREAD_CSTR;
     if (wpt_class != 0) {
-      res->description = res->url;
-      res->url = NULL;
+      res->description = xstrdup(res->url.toUtf8().data());
+      res->url.clear();
     }
   } else { // if (gdb_ver >= GDB_VER_3)
     int i, url_ct;
@@ -1342,7 +1342,7 @@ write_waypoint(
     FWRITE(zbuf, 3);
     FWRITE(zbuf, 4);
     descr = (wpt_class < gt_waypt_class_map_point) ?
-            wpt->url : wpt->description;
+            wpt->url.toUtf8().data() : wpt->description;
     if ((descr != NULL) && (wpt_class >= gt_waypt_class_map_point) && \
         (strcmp(descr, wpt->shortname) == 0)) {
       descr = NULL;
@@ -1378,7 +1378,7 @@ write_waypoint(
       cnt++;
     }
     for (url_next = wpt->url_next; (url_next); url_next = url_next->url_next)
-      if (url_next->url) {
+      if (!url_next->url.isEmpty()) {
         cnt++;
       }
     FWRITE_i32(cnt);
@@ -1386,8 +1386,8 @@ write_waypoint(
       FWRITE_CSTR(wpt->url);
     }
     for (url_next = wpt->url_next; (url_next); url_next = url_next->url_next)
-      if (url_next->url) {
-        FWRITE_CSTR(url_next->url);
+      if (!url_next->url.isEmpty()) {
+        FWRITE_CSTR(url_next->url.toUtf8().data());
       }
   }
 
@@ -1645,7 +1645,7 @@ write_waypoint_cb(const waypoint* refpt)
 
   if ((test != NULL) && (route_flag == 0)) {
     if ((str_not_equal(test->notes, refpt->notes)) ||
-        (str_not_equal(test->url, refpt->url))) {
+        test->url.compare(refpt->url)) {
       test = NULL;
     }
   }
index 27c192e0c14c15fdd38575f5d16429f7c190d641..57c154fe7e6fad784538c73784924528fd0438b7 100644 (file)
@@ -110,7 +110,7 @@ html_disp(const waypoint* wpt)
   if (strcmp(wpt->description, wpt->shortname)) {
     if (wpt->hasLink()) {
       char* d = html_entitize(wpt->description);
-      gbfprintf(file_out, "<a href=\"%s\">%s</a>", wpt->url, d);
+      gbfprintf(file_out, "<a href=\"%s\">%s</a>", wpt->url.toUtf8().data(), d);
       xfree(d);
     } else {
       gbfprintf(file_out, "%s", wpt->description);
index 35eae91ba9d60b986063be3518fc47651655c850..0a23fbd424b05339db899ce842608590900ccf74 100644 (file)
@@ -1390,7 +1390,7 @@ char* kml_geocache_get_logs(const waypoint* wpt)
   return r;
 }
 
-static void kml_write_data_element(const char* name, const char* value)
+static void kml_write_data_element(const char* name, const QString& value)
 {
   writer.writeStartElement("Data");
   writer.writeAttribute("name", name);
@@ -1557,8 +1557,10 @@ static void kml_waypt_pr(const waypoint* waypointp)
   if (waypointp->hasLink()) {
     writer.writeEmptyElement("snippet");
     if (waypointp->hasLinkText()) {
-      char* odesc = xml_entitize(waypointp->url);
-      char* olink = xml_entitize(waypointp->url_link_text);
+      // FIXME(robertlipe): these call to xml_entitize are suspicios with 
+      // new XML serializer.
+      char* odesc = xml_entitize(waypointp->url.toUtf8().data());
+      char* olink = xml_entitize(waypointp->url_link_text.toUtf8().data());
       writer.writeStartElement("description");
       writer.writeCDATA(QString("<a href=\"%1\">%2</a>").arg(odesc, olink));
       writer.writeEndElement(); // Close description tag
index 09573ab940c8dec9e5fc6e598603ec47bfe3f55f..c46e50bc00636c8669ad2d37b5e3e81dcbd35524 100644 (file)
@@ -174,7 +174,7 @@ lmx_end_tag(int tag, int indent)
 }
 
 static void
-lmx_write_xml(int tag, const char* data, int indent)
+lmx_write_xml(int tag, const QString& data, int indent)
 {
   lmx_start_tag(tag, indent);
 
@@ -182,7 +182,7 @@ lmx_write_xml(int tag, const char* data, int indent)
     gbfputc(0x03, ofd); // inline string follows
     gbfputcstr(data, ofd);
   } else {
-    char* tmp_ent = xml_entitize(data);
+    char* tmp_ent = xml_entitize(data.toUtf8().data());
     gbfputs(tmp_ent, ofd);
     xfree(tmp_ent);
   }
index c879d562b979014cf5fb834a8277dc3efd176403..761938f8e3bb4f8a6939d878fc7bc6bddd876f1e 100644 (file)
@@ -1013,7 +1013,7 @@ mmo_finalize_rtept_cb(const waypoint* wptref)
       wpt->notes = xstrdup(wpt2->notes);
     }
     if (wpt2->hasLink()) {
-      wpt->notes = xstrdup(wpt2->url);
+      wpt->notes = xstrdup(wpt2->url.toUtf8().data());
     }
 
     wpt->proximity = wpt2->proximity;
@@ -1310,7 +1310,7 @@ mmo_write_wpt_cb(const waypoint* wpt)
 
   if (wpt->hasLink()) {
     str = xstrdup("_FILE_ ");
-    str = xstrappend(str, wpt->url);
+    str = xstrappend(str, wpt->url.toUtf8().data());
     str = xstrappend(str, "\n");
   } else {
     str = xstrdup("");
index 37e948485fb36befb38bf4712241e7b616bb15cd..f2bb214a483acaf01ce4d4168a0398562587801c 100644 (file)
@@ -141,7 +141,7 @@ enum {
   RCR,
   MILLISECOND,
   DISTANCE,
-} DATA_TYPES;
+} /* DATA_TYPES */;
 
 struct log_type {
   int id;
index 1d9b9eaa48ec43eeacc35ff7ed12aeb62384f741..848f999d7fc682ba0070ffbefb119cb9f5878b06 100644 (file)
@@ -129,7 +129,7 @@ nav_start(void* data, const XML_Char* xml_el, const XML_Char** xml_attr)
 
         id = atoi(ap[1]);
         xasprintf(&wpt_tmp->shortname, "N%05X", id);
-        xasprintf(&wpt_tmp->url, "%s%d", NC_URL, id);
+        wpt_tmp->url = QString(NC_URL) + QString::number(id);
       } else if (0 == strcmp(ap[0], "name")) {
         wpt_tmp->description = xstrdup(ap[1]);
       } else if (0 == strcmp(ap[0], "user_name")) {
index 58911d0ffdf3a1258f0dc41d536b4b89c832c06f..df7d9f39d99ad1e5f217e8dec09b059337bd9942 100644 (file)
@@ -220,7 +220,7 @@ tmpro_waypt_pr(const waypoint * wpt)
             wpt->altitude,
             colour,
             icon,
-            wpt->hasLink() ? wpt->url : ""
+            wpt->hasLink() ? wpt->url.toUtf8().data() : ""
            );
 
 
index b0e5866849ae59045be00579aafeaef47dce8541..7c503198d92c2a4807cae081ddb7638a5c473b7b 100644 (file)
@@ -105,7 +105,7 @@ vcf_disp(const waypoint *wpt)
   gbfprintf(file_out, "ADR:%c%d %06.3f %c%d %06.3f\n", wpt->latitude < 0 ? 'S' : 'N',  abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint));
 
   if (wpt->hasLink()) {
-    gbfprintf(file_out, "URL:%s\n", wpt->url);
+    gbfprintf(file_out, "URL:%s\n", wpt->url.toUtf8().data());
   }
 
   gbfprintf(file_out, "NOTE:");
index f02d2e9def2675802e6b8588aa20047ef34bad86..2f5b89dc5581dc4a13039dd05e8755ec759c4bd8 100644 (file)
@@ -64,17 +64,12 @@ waypt_dupe(const waypoint *wpt)
   if (wpt->notes) {
     tmp->notes = xstrdup(wpt->notes);
   }
-  if (wpt->url) {
-    tmp->url = xstrdup(wpt->url);
-  }
-  if (wpt->url_link_text) {
-    tmp->url_link_text = xstrdup(wpt->url_link_text);
-  }
+
+  tmp->url = (wpt->url);
+  tmp->url_link_text = wpt->url_link_text;
 
   for (url_link* url_next = wpt->url_next; url_next; url_next = url_next->url_next) {
-    waypt_add_url(tmp,
-                  (url_next->url) ? xstrdup(url_next->url) : NULL,
-                  (url_next->url_link_text) ? xstrdup(url_next->url_link_text) : NULL);
+    waypt_add_url(tmp, url_next->url, url_next->url_link_text);
   }
 
   tmp->icon_descr = wpt->icon_descr;
@@ -399,24 +394,12 @@ waypt_free(waypoint *wpt)
   if (wpt->notes) {
     xfree(wpt->notes);
   }
-  if (wpt->url) {
-    xfree(wpt->url);
-  }
-  if (wpt->url_link_text) {
-    xfree(wpt->url_link_text);
-  }
   if (wpt->url_next) {
     url_link *url_next;
 
     for (url_next = wpt->url_next; url_next;) {
 
       url_link *tonuke = url_next;
-      if (tonuke->url) {
-        xfree(tonuke->url);
-      }
-      if (tonuke->url_link_text) {
-        xfree(tonuke->url_link_text);
-      }
       url_next = tonuke->url_next;
       xfree(tonuke);
     }
@@ -509,7 +492,7 @@ waypt_restore(signed int count, queue *head_bak)
 }
 
 void
-waypt_add_url(waypoint *wpt, char *link, char *url_link_text)
+waypt_add_url(waypoint *wpt, const QString& link, const QString& url_link_text)
 {
   if ((link == NULL) && (url_link_text == NULL)) {
     return;
@@ -521,7 +504,7 @@ waypt_add_url(waypoint *wpt, char *link, char *url_link_text)
     wpt->url_link_text = url_link_text;
   } else {
     url_link *tail;
-    url_link *new_link = (url_link*) xcalloc(sizeof(url_link), 1);
+    url_link *new_link = new url_link;
     new_link->url = link;
     new_link->url_link_text = url_link_text;